FTPClient ftp;

open() {
    ftp = new FTPClient();
    //添加控制台ftp操作过程日志打印
    ftp.addProtocolCommandListener(new PringCommandListener(new PrintWriter(System.out)));
    //设置超时时间
    ftp.setDefualtTimeout(3000);
    ftp.setConnectTimeout(3000);
    ftp.setDAtaTimeout(3000);
    //设置被动连接模式
    ftp.enterLocalPassiveMode();
}

//文件上传
upload(String relativePath, String fileName, InputStream inputStream) {
    String filePath = basePath+relativePath+"/";
    if (ftp.cwd(filePath) == 550) {
        filePath = basePath;
        //目录只能一级级创建
        for (String s : relativePath.split("/")) {
            filePath += s+"/";
            if (ftp.cwd(filePath) == 550) {
                ftp.makeDirectory(filePath);
            }
        }
        return ftp.storeFile(filePath+fileName,inputStream);
    }
    return ftp.storeFile(filePath+fileName,inputStream);
}

//使用流程
FtpClient ftpClient = new FtpClient(参数...);
try {
    ftpClient.open();
    do something...
    ftpClient.logout();
} finally {
   ftpClient.disconnect();
}
    